package com.example.demo;

import com.example.demo.proxy.MyService;
import com.example.demo.proxy.MyServiceImpl;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

@EnableAspectJAutoProxy(proxyTargetClass = false)
@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(DemoApplication.class, args);
        // 获取 MyService 实现
        MyService myService = context.getBean(MyService.class);

        // 调用方法
        myService.doSomething();
        myService.doSomethingElse();

        // 调用 privateMethod，注意 CGLIB 代理能否拦截这个方法
        if (myService instanceof MyServiceImpl) {
            ((MyServiceImpl) myService).privateMethod(); // 通过强制转换来调用
        }
    }

}
